<template>
	<el-card>
		<!-- 搜索 -->
		<el-form :model="searchData" inline ref="searchFormRef" v-resize="searchResize" label-width="70px">
			<el-form-item label="商品名称" prop="goodsName">
				<el-input v-model="searchData.goodsName" placeholder="请输入商品名称" clearable></el-input>
			</el-form-item>

			<el-form-item label="状态" prop="billStatus">
				<el-select v-model="searchData.billStatus"  clearable placeholder="请选择订单状态" style="wdith:100%">
					<el-option :value="0" label="待选择"></el-option>
					<el-option :value="1" label="已完成"></el-option>
					<el-option :value="2" label="待制作"></el-option>
				</el-select>
			</el-form-item>
			
			<el-form-item>
				<el-button icon="el-icon-search" type="primary" @click="searchClick">搜索</el-button>
				<el-button icon="el-icon-refresh" @click="resetClick">重置</el-button>
				<!-- <el-button icon="el-icon-plus" type="success" v-has="'sys:bill:add'" @click="addShowClick">新增</el-button> -->
			</el-form-item>
		</el-form>
		<!-- 表格渲染 -->
		<YwTable ref="tableRef" :searchData="searchData" :tableProps="tableProps" api="sysBillFindAllByPage">
			<el-table-column slot="table_oper" label="操作" fixed="right" width="170px">
				<template v-slot="scope">
					
					<el-button type="text" icon="el-icon-edit" @click="editShowClick(scope.row)"
						v-has="'sys:bill:edit'">修改</el-button>
					<el-button type="text" icon="el-icon-delete" @click="deleteClick(scope.row)"
						v-has="'sys:bill:delByIds'">删除</el-button>
					<el-button type="text" icon="el-icon-folder-opened" @click="toChoosePic(scope.row)"
					v-has="'sys:bill:selectChoose'">已选图片</el-button>
				</template>
			</el-table-column>
		</YwTable>

		<!-- 添加/修改 -->
		<YwDialog @confirm="confirmClick" width="650px" ref="ywDialogRef" title="修改信息">
			<template slot="form">
				<el-form :model="curData" inline ref="curFormRef" label-width="95px" :show-message="false">
				
					<el-form-item label="商品名称" prop="goodsName" required>
						<el-input v-model="curData.goodsName" placeholder="请输入商品名称"></el-input>
					</el-form-item>

					<el-form-item label="商品价格" prop="billPrice" required>
						<el-input v-model="curData.billPrice" placeholder="请输入商品价格"></el-input>
					</el-form-item>

					<el-form-item label="状态" prop="billStatus" required>
						
						<el-radio-group v-model="curData.billStatus" >
							<el-radio v-for="dict in dict.type.billStatus" :key="dict.value" :label="dict.value">
								{{dict.label}}
							</el-radio>
						</el-radio-group>
					</el-form-item>

				</el-form>
			</template>
		</YwDialog>

	</el-card>
</template>

<script>
	export default {
		dicts: ["billStatus"],
		data() {
			return {
				//搜索条件
				searchData: {
					goodsName: null,
					billStatus:null,
					
				},
				//添加信息数据
				//修改信息数据
				//表单的值
				curData: {
					goodsName: null,
					kgName: null,
					studentName: null,
					billPrice:0,
					billStatus: 0,
					
				},
				//表格数据
				tableProps: [{
						label: "商品名称",
						prop: "goodsName"
					},
					{
						label: "商品价格",
						prop: "billPrice"
					},
					{
						label: "幼儿园名称",
						prop: "kgName"
					},
					{
						label: "学生姓名",
						prop: "studentName"
					},
					{
						label: "订单状态",
						prop: "billStatus",
						type: "tagDict",
						result: () => {
							return this.dict.type.billStatus
						}
						
					},
					{
						label: "创建时间",
						prop: "createTime",
						width: "160px"
					},
				
					
				],
				
			};
		},
		mounted() {
			console.log("===========",this.dict.type.billStatus)
			this.$nextTick(() => {
				this.$refs.tableRef.shuaxin(this.searchData)
			})

		},
		methods: {
			//搜索重置
			searchResize(data) {
				this.$refs.tableRef.refreshSize(data)
			},

			
			//添加/修改表单的确认按钮
			confirmClick() {
				let data = JSON.parse(JSON.stringify(this.curData))
				this.$refs.curFormRef.validate(async (valid) => {
					if (valid) {
						if (data.id) {
							//修改操作
							await this.$api.sysBillEdit(data);
							
						} else {
							//添加操作
							await this.$api.sysBillAdd(data)
						}
						this.$refs.ywDialogRef.close()
						this.searchClick()
					}
				});
			},
			//删除事件
			deleteClick(row) {
				this.$common.msgBoxDel(() => {
					this.$api.sysBillDelByIds(row.id).then(res => {
						this.searchClick();
					});
				})
			},
			//跳转至已选图片
			toChoosePic(row){
				this.$router.push({
					path: '/choosePic',
					query:{
						id:row.id
					}
				})
			},

			// //新增按钮
			// addShowClick() {
			// 	this.curData = {
			// 		goodsName: null,
			// 		billStatus: null,
			// 		address: null,
			// 		consigneeName: null,
					
				
			// 	}
			// 	this.$refs.ywDialogRef.open()
			// },
			//修改按钮
			editShowClick(row) {
				//给表单赋值

				this.$api.sysBillFindById(row.id).then((result) => {
					this.curData = result;//实现表单赋值
				})	
				this.$refs.ywDialogRef.open()
			},

			//搜索按钮
			searchClick() {
				this.$refs.tableRef.shuaxin(this.searchData)
			},
			//重置按钮
			resetClick() {
				this.$refs.searchFormRef.resetFields();
				this.searchClick()
			},
		},
	};
</script>

<style lang="scss" scoped>
</style>
